<template>
    <view style="display: flex; flex-direction: column; height: 100vh">
		<xmInfo
		    :projectno="itemContent.projectno"
		    :projectname="itemContent.projectname"
		  ></xmInfo>
		  <view style="flex: 1;  overflow: scroll">
		<scroll-view class="scroll-list" scroll-y="true" @scrolltolower="loadMore" :refresher-enabled="true"
			:refresher-triggered="triggered" @refresherrefresh="refresherrefresh">
        <!-- <view class="cu-card"> -->
            <view class="cu-card cu-item shadow"  v-for="(item,index) in list" :key="item.id">
				<view
				    class="cu-form-group"
				    style="display: flex; justify-content: space-between"
				  >
				    <view
				      style="
				        display: inline-block;
				        padding: 5px;
				        background: #3e97b0;
				        color: #fff;
				        width: 40px;
				        text-align: center;
				        font-style: italic;
				        font-weight: bold;
				      "
				    >
				      {{ index + 1 }}
				    </view>
				   
					<view class="text-xl text-bold" style="margin-left: 10px;">{{ item.createTime }}</view>
				  </view>
				  <view class="cu-form-group flex-wrap">
				    <!-- <view class="title">日志内容</view> -->
				    <view>{{ item.logContent }}</view>
				  </view>
				  <view class="cu-form-group flex-wrap">
				    <view class="title"></view>
				    <view>{{ item.operatorName }}</view>
				  </view>
				   
				</view>
            
        <!-- </view> -->
		<view v-if="list.length" class="loadmore">
			<u-loadmore :status="loadStatus"></u-loadmore>
		</view>
		<u-empty v-if="!list.length"></u-empty>
		</scroll-view>
        
		<!-- <view style="height: 80px"></view>
		<view class="btn-group cu-bar foot" style="height: 80px">
		    <button class="cu-btn bg-green shadow-blur"@click="add('')">
		        <text class="cuIcon-add"></text> 上传
		    </button>
		</view> -->
		</view>
    </view>
</template>
<script>
import xmInfo from "@/pages/zfgs/index/componetns/xmInfo.vue";
  export default{
  components: {xmInfo },
    data(){
        return{
			triggered: false,
			loadStatus: 'loadmore',
			query: {
				pageNo: 1,
				pageSize: 20,
			},
			itemContent:{},
            imgList: ["http://192.168.1.49:8080/app/static/image/zfgs/zfgs1.jpg","http://192.168.1.49:8080/app/static/image/zfgs/zfgs2.jpg"],
            list:[],
			totalList:[],
        }
    },
	onShow() {
		this.query.pageNo = 1;
		this.loadList();
	},
	onLoad(e) {
	  if (typeof e.item !== "undefined") {
	    try {
	      this.itemContent = JSON.parse(e.item);
		 this.query.projectno = this.itemContent.projectno
	      console.log(this.itemContent);
	    } catch (error) {
	      console.error("Failed to parse item:", error);
	    }
	  } else {
	    console.warn("Item is undefined.");
	  }
	},
	
    methods:{
		async refresherrefresh() {
			this.triggered = true
			this.query.pageNo = 1;
			await this.loadList()
			this.triggered = false
		},
		loadList(type) {
			this.$u.api.zfgs.attachLog(this.query).then(res => {
				if(Array.isArray(res)){
					if (res.length < 20 || res.length == 0) {
						this.loadStatus = "nomore";
						this.list = res;
						this.totalList = res;
					}else{
						this.totalList = res;
						this.list =  this.totalList.slice(0, 20)
					}
				}else{
					// this.$u.toast(res.message);
				}
				
				// var data = res.data;
				// if (type == "add") {
				// 	for (var i = 0; i < data.length; i++) {
				// 		this.list.push(data[i])
				// 	}
				// } else {
				// 	this.list = data;
				// }
			})
		},
		loadMore() {
			this.loadStatus = "loading";
			setTimeout(() => {
				this.query.pageNo += 1;
				let num = (this.query.pageNo - 1) * 20
				let arr =  this.totalList.slice(num, num+20)
				if(arr.length < 20 || arr.length == 0){
					this.loadStatus = "nomore";
				}
				for (var i = 0; i < arr.length; i++) {
					this.list.push(arr[i])
				}
				
				// this.loadList("add");
			}, 100);
		},
		
        add(item){
            console.log(item,'item')
            if(item){
                uni.navigateTo({
                    url: '/pages/zfgs/proj/zg/pmRectification/form?id='+item.id
                })
            }else{
                uni.navigateTo({
                    url: '/pages/zfgs/proj/zg/pmRectification/form?projectno='+this.itemContent.projectno + '&name='+this.itemContent.projectname + "&id=''"
                })
            }
        },
    }
  }

</script>
<style lang="scss" scoped>
	/deep/ .u-progress.data-v-0d33af60 {
		display: none;
	}
	/deep/.u-input__input.data-v-460c1d26 {
	    text-align: right;
	}
.cu-btn {
  font-size: 16px;
  height: 40px;
}
.foot{
    background: #fff;
}
.cu-item{
  flex-wrap: wrap;
  padding: 15px !important;
}
.title{
    flex-shrink: 0;
}
.grid-square{
    margin-bottom: 0 !important;
}
::v-deep .u-input__input{
	text-align: right;
}
</style>